import React from 'react';
import { Route, Redirect } from 'react-router-dom';

export default ({
  exact,
  redirect,
  path,
  component: Comp,
  routes = []
}) => {
  if (redirect) {
    return (
      <Redirect exact={exact} from={path} to={redirect} />
    );
  }
  return (
    <Route
      exact={exact}
      path={path}
      render={(props) => {
        if (Comp) {
          return (
            <Comp {...props} routes={routes} />
          );
        }
      }}
    />
  );
};
